package com.example.demo;


import com.example.demo.entity.Bill;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.context.junit4.SpringRunner;

import java.time.Duration;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;

@RunWith(SpringRunner.class)
@SpringBootTest
public class TestRedis {
    @Autowired
    RedisTemplate redisTemplate;

    @Test
    public void testRedis() {


        List<Bill> bills = new ArrayList();
        for (int i = 0; i < 5; i++) {

            Bill bill1 = new Bill();
            bill1.setGoodsName("手机" + i);
            bill1.setCreateTime(new Date());
            bills.add(bill1);
        }
        redisTemplate.opsForValue().set("user", "中文",5, TimeUnit.SECONDS);
        redisTemplate.opsForValue().set("bills", bills);
        Bill bill = (Bill) redisTemplate.opsForValue().get("bill");
    }


}
